//
//  YLMallGoodExchangeBottomTab.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/6.
//  Copyright © 2017年 she1323. All rights reserved.
//  立即兑换底部

#import "YLMallGoodExchangeBottomTab.h"
#import <Masonry.h>
#import "YLGlobeHeader.h"
@interface YLMallGoodExchangeBottomTab ()
@property (nonatomic, weak) UIView *baseTabView;

@property (nonatomic, weak) UILabel *titleLabel;
@end

@implementation YLMallGoodExchangeBottomTab

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        _totalPrice = NO;
        _exchangeSubject = [RACSubject subject];
        [self setUpTab];
    }
    return self;
}

- (void)setUpTab
{
    __weak typeof(self) weakSelf = self;
    UIView *baseTabView = [[UIView alloc] init];
    _baseTabView = baseTabView;
    [self addSubview:baseTabView];
    
    [baseTabView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.mas_equalTo(weakSelf);
    }];
    
    
    
    
    UIView *line = [[UIView alloc] init];
    [baseTabView addSubview:line];
    line.alpha = 0.3;
    line.backgroundColor = YLLineColor;
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(baseTabView);
        make.height.mas_equalTo(1);
    }];
    
    baseTabView.backgroundColor = YLColor(248, 249, 252);
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [self addSubview:titleLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(baseTabView);
        make.left.mas_equalTo(baseTabView).mas_offset(20);
        
    }];
    
    titleLabel.text = @"单价:0积分";
    _titleLabel = titleLabel;
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        [weakSelf.exchangeSubject sendNext:nil];
    }];
    [self addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(baseTabView).mas_offset(20);
        make.bottom.mas_equalTo(baseTabView).mas_offset(-20);
        make.width.mas_equalTo(80);
        make.right.mas_equalTo(baseTabView).mas_offset(-10);
        
    }];
    
    button.layer.masksToBounds = YES;
    button.titleLabel.font = [UIFont systemFontOfSize:13.0f];
    [button setTitle:@"立即兑换" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    button.backgroundColor = YLLOrgColor;
    button.layer.cornerRadius = 3.0;
}

- (void)setNeetPoint:(NSString *)neetPoint
{
    _neetPoint = neetPoint;
    if (!_totalPrice) {
        NSString *s = [NSString stringWithFormat:@"单价: %@ 积分", neetPoint];
        
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:s];
        [str addAttribute:NSForegroundColorAttributeName value:YLMainColor range:NSMakeRange(4, neetPoint.length)];
        _titleLabel.attributedText = str;
    } else {
        NSString *s = [NSString stringWithFormat:@"实付款: %@ 积分", neetPoint];
        
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:s];
        [str addAttribute:NSForegroundColorAttributeName value:YLMainColor range:NSMakeRange(5, neetPoint.length)];
        _titleLabel.attributedText = str;
    }
    
}






@end
